<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <input type="text" class="user">
    <br>
    <input type="password" class="pwd">
    <br>
    <button>登录</button>

    <script src="../js/ajax.js"></script>

    <script>

        const oBtn = document.querySelector('button') ;
        const oUser = document.querySelector('.user') ;
        const oPwd = document.querySelector('.pwd') ;

        oBtn.onclick = function() {
            const username = oUser.value ;
            const userpwd = oPwd.value ;

            if(username && userpwd) {
                ajax({
                    type : 'post' , 
                    url : '../php/login.php' ,
                    data : {
                        username ,
                        userpwd 
                    } ,
                    cb : d => {
                        console.log(d);
                        const {status , msg} = d ;
                        if(status) {
                            alert(msg) ;
                            // 跳转至其他页面
                            // 把登录的账号保存
                            localStorage.setItem('LOGIN_USER' , username) ;
                        } else {
                            alert(msg) ;
                        }
                    }
                })
            }
        }





        

    </script>
    
</body>
</html>